PargoDesktop = new Ext.app.App({
	init :function(){
		Ext.QuickTips.init();
	},

	getModules : function(){
		return [
            new PargoDesktop.ContentBrowserWindow(),
			new PargoDesktop.ContentObjectWindow(),
		];
	},

    // config for the start menu
    getStartConfig : function(){
        return {
            title: 'Username',
            iconCls: 'user',
            toolItems: [{
                text:'Settings',
                iconCls:'settings',
                scope:this
            },'-',{
                text:'Logout',
                iconCls:'logout',
                scope:this
            }]
        };
    }
});

PargoDesktop.ContentBrowserWindow = Ext.extend(Ext.app.Module, {
    id:'content-browser-window',
    init : function(){
        this.launcher = {
            text: 'Content Browser Window',
            iconCls:'accordion',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('content-browser-window');
        if(!win){
            win = desktop.createWindow({
                id: 'content-browser-window',
                title: 'Content Browser Window',
                width:250,
                height:400,
                iconCls: 'accordion',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                tbar:[{
                    tooltip:'Add content object',
                    iconCls:'add'
                },' ',{
                    tooltip:'Remove the selected content object',
                    iconCls:'remove'
                },'-',{
                    tooltip: {title:'Help', text:'Show help.'},
                    iconCls:'help'
                }],

                layout:'accordion',
                border:false,
                layoutConfig: {
                    animate:false
                },

                items: [
                    new Ext.tree.TreePanel({
                        id:'content-tree',
                        title: 'Content objects',
                        loader: new Ext.tree.TreeLoader(),
                        rootVisible:false,
                        lines:false,
                        autoScroll:true,
                        tools:[{
                            id:'refresh',
                            on:{
                                click: function(){
                                    var tree = Ext.getCmp('contnet-tree');
                                    tree.body.mask('Loading', 'x-mask-loading');
                                    tree.root.reload();
                                    tree.root.collapse(true, false);
                                    setTimeout(function(){ // mimic a server call
                                        tree.body.unmask();
                                        tree.root.expand(true, true);
                                    }, 1000);
                                }
                            }
                        }],
                        root: new Ext.tree.AsyncTreeNode({
                            text:'Listing',
                            children:[{
                                text:'Folder 1',
                                expanded:true,
                                children:[{
                                    text:'Doc 1',
                                    iconCls:'document',
                                    leaf:true
                                },{
                                    text:'Doc 2',
                                    iconCls:'document',
                                    leaf:true
                                },{
                                    text:'Doc 3',
                                    iconCls:'document',
                                    leaf:true
                                },{
                                    text:'Image 1',
                                    iconCls:'image',
                                    leaf:true
                                },{
                                    text:'Image 2',
                                    iconCls:'image',
                                    leaf:true
                                },{
                                    text:'File 1',
                                    iconCls:'file',
                                    leaf:true
                                },{
                                    text:'File 2',
                                    iconCls:'file',
                                    leaf:true
                                }]
                            },{
                                text:'News',
                                expanded:true,
                                children:[{
                                    text:'News Item 1',
                                    iconCls:'news-item',
                                    leaf:true
                                },{
                                    text:'News Item 1',
                                    iconCls:'news-item',
                                    leaf:true
                                },{
                                    text:'News Item 1',
                                    iconCls:'news-item',
                                    leaf:true
                                },{
                                    text:'News Item 1',
                                    iconCls:'news-item',
                                    leaf:true
                                }]
                            }]
                        })
                    }), {
                        title: 'Search',
                        html:'Search form for content objects',
                        autoScroll:true
                    }
                ]
            });
        }
        win.show();
    }
});

PargoDesktop.ContentObjectWindow = Ext.extend(Ext.app.Module, {
    id:'content-object-window',
    init : function(){
        this.launcher = {
            text: 'Content Object Window',
            iconCls:'tabs',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('content-object-window');
        if(!win){
            win = desktop.createWindow({
                id: 'content-object-window',
                title:'Content Object Window',
                width:740,
                height:480,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,
                border:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.TabPanel({
                        activeTab:0,

                        items: [{
                            title: 'Preview',
                            header:false,
                            html : 'Iframe for contnet preview.',
                            border:false
                        },{
                            title: 'Edit',
                            header:false,
                            html : 'Form for editing basic object properties.',
                            border:false
                        },{
                            title: 'Contents',
                            header:false,
                            html : 'Listing of content object inside this container.',
                            border:false
                        },{
                            title: 'Metadata',
                            header:false,
                            html : 'Show object matadata.',
                            border:false
                        }]
                    })
            });
        }
        win.show();
    }
});
